<template>
  <div class="page index" ref="page" @scroll="pageScroll">
    <van-sticky>
      <div :class="navbgClass">
        <van-search
          slot="title"
          placeholder="输入名称搜索"
          shape="round"
          background="transparent"
          v-model="value"
          @search="onSearch"
          @cancel="onCancel"
        />
      </div>
    </van-sticky>
    <div v-for="item in fourads" :key="item.id" class="normal-task">
      <van-row gutter="5">
        <van-col span="6">
          <van-image
                  round
                  width="3rem"
                  height="3rem"
                  src="https://img01.yzcdn.cn/vant/cat.jpeg"
          />
        </van-col>
        <van-col span="12" class="content">
          <div>Eric</div>
          <div class="task">简单任务</div>
          <div class="task">已做12人，剩18人</div>
        </van-col>
        <van-col span="6" class="price">
          ￥20.22
        </van-col>
      </van-row>
    </div>
    <van-divider>到底了哦~</van-divider>
  </div>
</template>
<script >
export default {
  name: "product",
  data() {
    return {
      is_loaded: false,
      value:'',
      fourads:[
        {id:1,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:2,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:3,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:4,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:5,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:6,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:7,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
        {id:8,url:'2dfa',image:'/static/logo.png',title:'打发撒旦'},
      ],
      navbgClass: "bg-transparent"
    };
  },
  mounted() {
    // this.loadData();
  },
  methods: {
    pageScroll() {
      let scrollTop = this.$refs.page.scrollTop;
      if (scrollTop >= window.innerWidth * 0.4) {
        this.navbgClass = "search-box";
      } else {
        this.navbgClass = "search-box bg-transparent";
      }
    },
    loadData() {
    },
    toUrl(url) {
      if(!url){
        this.$toast('功能即将上线~')
        return;
      }
      if(url.indexOf('http://')===0 || url.indexOf('https://')===0){
        location.href = url;
      }else{
        this.$router.push(url)
      }
    },
    onSearch() {
      this.$router.push('/search?keyword='+encodeURIComponent(this.value))
    },
    onCancel() {
      this.value = ''
    },
    sorry() {
      this.$toast('功能即将上线~')
    }
  }
};
</script>
<style lang="scss" >
.index {
  .normal-task{
    padding-top: 1rem;
    padding-bottom: 1rem;
    margin-top: 1rem;
    background: #fff;
    text-align: center;
    .content{
      text-align: left;
      .task{
        color: gray;
      }
    }
    .price{
      color: red;
      font-size: 1rem;
      font-weight: bold;
    }
  }
  .search-box {
    background: #fff;
    .van-search__content {
      background-color: #ededed;
    }
    &.bg-transparent {
      background: transparent;
    }
  }
}
</style>
